package com.smh.a17exerciseDemo4;

import java.util.ArrayList;

public class MyThread extends Thread {
    ArrayList<Double> list;

    public MyThread(ArrayList<Double> list) {
        this.list = list;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (MyThread.class) {
                if (list.size() == 0) {
                    System.out.println(Thread.currentThread().getName() + "没抢到");
                    break;
                } else {
                    Double money = list.get(0);
                    list.remove(0);
                    System.out.println(Thread.currentThread().getName() + "抢到了" + money + "元");
                    break;
                }
            }
        }
    }
}
